/*** tabdata6.do

This do-file takes all of the tabular data and puts it into 
one large "wide" format file in which the unit of observation
is city05.

It creates the same set of variables indexed as follows:
XXXX_cp90a - city proper based on aggregating units
XXXX_cp90 - city proper based as much as possible on full geographies
XXXX_prefa - prefectures based on aggregating units
XXXX_prefb - prefectures based on adding CC and pref remainder
XXXX_pref - prefectures based as much as possible on full geographies

****/

clear
set more off
set mem 100m
capture log close
log using tabdata6.log, replace text

*** Create province identifiers within city05
use ..\..\data\tabular_data_BJ\generated\us123-census.dta
keep if year==1982 & cp90==1
sort city05
by city05: keep if _n==1
keep city05 province_code
replace province_code = 510000 if province_code==500000
sort city05
save xwtemp.dta, replace

*********** 1. Build 1990 City Propers based on aggregates ***********

use ..\..\data\tabular_data_BJ\generated\agg_cp90.dta
#delimit ;
keep city05 year promoted_ccity unpromoted_ccity a434-a193 aN*
gdp gdp_sector1 gdp_sector2 gdp_sector3 tot_pop 
fdi pop gdp_michigan givo area_paved_roads
ruralpop rurallabor va_sec1 va_sec2
totemp gdp_py fdi_py givo_py gdp_sect2 gdp_sect3 total_pop kmpr apr givo_soe givo_colt area fixinvest
ruralpop_fenxian rurallabor_fenxian gdp_fenxian gdp_sector1_fenxian gdp_sector2_fenxian
avgsalary avgsalary_michigan gdp_predf gdp_predc gdp_sect2_predf gdp_sect2_predc
a101-a452
c_totalPop c_emp c_f_* c_m_* c_rur_* c_urb_* c_emp_* asset_*;
#delimit cr

foreach X of varlist a434-gdp_sect2_predf {
rename `X' `X'_cp90a
}

reshape wide promoted_ccity unpromoted_ccity *_cp90a, i(city05) j(year)

foreach X of varlist *_cp90a* {
	qui: sum `X'
	 if r(N)==0 {
	 drop `X'
	}
}
sort city05
save cp90a.dta, replace


****** 2. 1990 City Propers based on adding aggregates to cpt **********

*Census Data
use ..\..\data\tabular_data_BJ\generated\cp90.dta
gen city05 = city_code
replace city05 = 421000 if city05==420400
#delimit ;
keep nmcenmq city05 year 
a101-a452;
#delimit cr
sort city05 year
save temp90.dta, replace

use ..\..\data\tabular_data_BJ\generated\cpt.dta
#delimit ;
keep city05 city_name year 
gdp gdp_sector1 gdp_sector2 gdp_sector3 tot_pop 
pop gdp_michigan gdp_sector2_mi gdp_sector3_mi givo area_paved_roads 
avgsalary avgsalary_michigan fdi_py givo_py
totemp gdp_py gdp_sect2 gdp_sect3 total_pop kmpr apr givo_soe givo_colt area fixinvest fdi
asset_*;
#delimit cr

sort city05 year
merge city05 year using temp90.dta
tab _merge if year==1990
** These are outside of the study area or county cities that are captured in the aggregated data
** _merge=1 is Hengshui which will show up later in the cp90a variables
drop if _merge==2
drop _merge

*** Rename all variables except those not in disag data, for which we don't have remainders
foreach X of varlist gdp-tot_pop pop-gdp_michigan a101-a452 asset_* {
  rename `X' a_`X'
}
gen a_gdp_predf = gdp_py
gen a_gdp_predc = gdp_py
gen a_gdp_sect2_predf = gdp_sect2
gen a_gdp_sect2_predc = gdp_sect2
save cpt.dta, replace

sort city05 year
merge city05 year using ..\..\data\tabular_data_BJ\generated\agg_cp90remain.dta
*** _merge=1 are cases where city propers are exactly the right unit
*** _merge=2 cases are only in 1982 or residual portions of promoted cities
*** _merge=3 are cases in which there are urban districts but the cp geography is different from the cp
tab year _merge
#delimit ;
keep year city05
a434-a193 gdp gdp_py gdp_sect2 gdp_sect3
gdp_sector1 gdp_sector2 gdp_sector3 tot_pop 
area fixinvest gdp_predf gdp_predc gdp_sect2_predf gdp_sect2_predc
pop gdp_michigan gdp_sector2_mi gdp_sector3_mi area_paved_roads 
totemp total_pop kmpr apr givo givo_soe givo_colt fdi
avgsalary avgsalary_michigan fdi_py givo_py asset_*
a101-a452
a_gdp a_gdp_sector1 a_gdp_sector2 a_gdp_sector3 a_tot_pop 
a_pop a_gdp_michigan
a_gdp_predf a_gdp_predc a_gdp_sect2_predf a_gdp_sect2_predc
a_a101-a_a452
a_asset_* _merge;
drop a_asset_g_qz aN* a271_274 a272_275;

*** For variables with rural information, piece together city proper + remainder;
foreach X of varlist gdp gdp_sector1 gdp_sector2 gdp_sector3 tot_pop 
pop gdp_michigan gdp_predf gdp_predc gdp_sect2_predf gdp_sect2_predc
a1* a2* a3* a4* asset_*{;
replace a_`X' = `X'+a_`X' if _merge==3;
rename a_`X' `X'_cp90;
drop `X';
};

#delimit cr

foreach X of varlist totemp-fdi_py gdp_sector2_mi-fdi {
replace `X' = . if _merge==3
rename `X' `X'_cp90
}

drop _merge
drop if year==1982

reshape wide *_cp90, i(city05) j(year)
*** These are all covered in cp90a
drop a*_cp902010
foreach X of varlist gdp_cp901990-gdp_sect2_predc_cp902010 {
	qui: sum `X'
	 if r(N)==0 {
	 drop `X'
	}
}

sort city05
save cp90.dta, replace


******* 3. 2005 definition prefectures *****************

use ..\..\data\tabular_data_BJ\generated\agg_pref.dta
#delimit ;
keep city05 year gdp gdp_sector1 gdp_sector2 gdp_sector3 tot_pop pop gdp_michigan
c_totalPop c_emp c_f_* c_m_* c_rur_* c_urb_* c_emp_* a* aN* gdp_pred* gdp_sect2_pred*
city_name;
#delimit cr
drop if city05==.
gen y05 = (year==2005)
sort city05 y05
by city05: replace city_name = city_name[_N]
drop y05
sort city05 year
foreach X of varlist a434-c_urb_ob_19to55_h_A2 gdp_pred* gdp_sect2_pred* {
rename `X' `X'_prefa
}
drop a453_prefa-a874_prefa
reshape wide a434_prefa-a193_prefa gdp_prefa-a452_prefa c_*_prefa gdp_pred* gdp_sect2_pred*, i(city05 city_name) j(year)
*** These are available in the pref data set
drop a*_prefa1990 *_predc_prefa2010 *_predf_prefa2010
foreach X of varlist a434_prefa1982-c_urb_ob_19to55_h_A2_prefa2010 {
	qui: sum `X'
	 if r(N)==0 {
	 drop `X'
	}
}

sort city05
save prefa.dta, replace


****** 4. 2005 Definition Prefectures Based on Earlier Year Aggregate Data *********

use ..\..\data\tabular_data_BJ\generated\pft.dta
#delimit ;
keep city05 year chg gdp gdp_sector1 gdp_sector2 gdp_sector3 
tot_pop tot_emp tot_emp_sect2 tot_emp_sect3 total_pop 
pop gdp_michigan gdp_sector2_mi gdp_sector3_mi totemp gdp_py gdp_sect2 gdp_sect3 emp_sect2 emp_sect3
total_pop givo givo_soe givo_colt fdi area culland cultiland
num_car bus_trol asset_*
a101-a452;
#delimit cr

drop if city05==.
keep if year==1990|year==1995|year==2000|year==2005|year==2010

foreach X of varlist chg gdp-a452 asset_* {
rename `X' `X'_pref
}

keep city05 year gdp_pref-a420_pref chg_pref asset_*_pref
reshape wide gdp_pref-a420_pref chg_pref asset_*_pref, i(city05) j(year)

foreach X of varlist gdp_pref1990-chg_pref2010 {
	qui: sum `X'
	 if r(N)==0 {
	 drop `X'
	}
}
sort city05
save pref.dta, replace


**************** 5. Prefectures by adding prefec remainders to city propers ********************

use cpt.dta
sort city05 year
merge city05 year using ..\..\data\tabular_data_BJ\generated\agg_noncpt.dta
drop if city05==.
*** sometimes no city, sometimes no remainder
tab _merge
#delimit ;
keep city05 year _merge
gdp gdp_sector1 gdp_sector2 gdp_sector3 tot_pop 
pop gdp_michigan
gdp_predf gdp_predc gdp_sect2_predf gdp_sect2_predc
a101-a452
a_gdp a_gdp_sector1 a_gdp_sector2 a_gdp_sector3 a_tot_pop 
a_pop a_gdp_michigan
a_gdp_predf a_gdp_predc a_gdp_sect2_predf a_gdp_sect2_predc
a_a101-a_a452;
foreach X of varlist gdp gdp_sector1 gdp_sector2 gdp_sector3 tot_pop pop 
gdp_michigan gdp_predf gdp_predc gdp_sect2_predf gdp_sect2_predc a1* a2* a3* a4* {;
replace a_`X' = `X'+a_`X' if _merge==3;
rename a_`X' `X'_prefb;
drop `X';
};
#delimit cr
drop _merge
drop a_a*
drop if year==1982

reshape wide gdp_prefb-gdp_sect2_predc_prefb, i(city05) j(year)

foreach X of varlist gdp_prefb1990-gdp_sect2_predc_prefb2010 {
	qui: sum `X'
	 if r(N)==0 {
	 drop `X'
	}
}

sort city05
save prefb.dta, replace


*********************** 6. Put All Data Sets Together ***************************

sort city05
merge city05 using cp90a.dta
tab _merge
drop _merge
sort city05
merge city05 using cp90.dta
tab _merge
drop _merge
sort city05
merge city05 using prefa.dta
tab _merge
drop _merge
sort city05
merge city05 using pref.dta
tab _merge
drop _merge
sort city05
merge city05 using ..\..\data\census\generated\card-inst.dta
tab _merge
drop _merge
rename city05 cc05
sort cc05
merge cc05 using ..\..\data\tabular_data_BJ\source\bus_trolley1991.dta
tab _merge
drop _merge

*** Merge on GDP Deflators
gen province05 = int(cc05/10000)
sort province05
merge province05 using ../../data/tabular_data_BJ/source/gdpdeflator_3years.dta
tab _merge
** Provinces outside of our study area
drop if _merge==2
drop _merge
sort cc05
merge cc05 using ../../data/tabular_data_BJ/source/gdpdeflator_2010.dta
tab _merge
drop _merge

** Drop 2008 variables
drop *2008
drop if cc05==0|cc05==.

** Merge on employment census data
sort cc05
merge cc05 using ..\..\data\empcensus\generated\emp_count_newind.dta
tab _merge
drop _merge



*************************** 7. Label Variables *************************

foreach loc in cp90a cp90 pref prefa prefb {
foreach yr in 1982 1990 1995 2000 2005 2010 {

cap label variable gdp_`loc'`yr' "(ind yrbk)"
cap label variable nnp_`loc'`yr' "(ind yrbk)"
cap label variable gdp_sector1_`loc'`yr' "(ind yrbk)"
cap label variable nnp_sector1_`loc'`yr' "(ind yrbk)"
cap label variable gdp_sector2_`loc'`yr' "(ind yrbk)"
cap label variable nnp_sector2_`loc'`yr' "(ind yrbk)"
cap label variable gdp_sector3_`loc'`yr' "(ind yrbk)"
cap label variable nnp_sector3_`loc'`yr' "(ind yrbk)"
cap label variable tot_pop_`loc'`yr' "(ind yrbk)"
cap label variable r08_gdp_`loc'`yr' "(ind yrbk)"
cap label variable r08_gdp_sector2_`loc'`yr' "(ind yrbk)"
cap label variable r08_nnp_sector2_`loc'`yr' "(ind yrbk)"
cap label variable r08_gdp_sector3_`loc'`yr' "(ind yrbk)"
cap label variable r08_nnp_sector3_`loc'`yr' "(ind yrbk)"
cap label variable r08_tot_pop_`loc'`yr' "(ind yrbk)"
cap label variable arrived_fdi_`loc'`yr' "(ind yrbk)"
cap label variable tot_emp_`loc'`yr' "(ind yrbk)"
cap label variable tot_emp_sect2_`loc'`yr' "(ind yrbk)"
cap label variable tot_emp_sect3_`loc'`yr' "(ind yrbk)"
cap label variable num_car_`loc'`yr' "(ind yrbk)"
cap label variable dust_ems_`loc'`yr' "(ind yrbk)"
cap label variable so2_`loc'`yr' "(ind yrbk)"
cap label variable giov_`loc'`yr' "(ind yrbk)"
cap label variable giov_soecol_`loc'`yr' "(ind yrbk)"
cap label variable tot_area_`loc'`yr' "(ind yrbk)"
cap label variable giov_new_`loc'`yr' "(ind yrbk)"
cap label variable giov_soecol_new_`loc'`yr' "(ind yrbk)"
cap label variable agr_mp_`loc'`yr' "Total Agricultural Machinery Power (10000 Kw) (Michigan)"
cap label variable pop_`loc'`yr' "Population at Year-end (10000 persons) (Michigan)"
cap label variable ruralpop_`loc'`yr' "Rural Population at yr end (10000 persons) (Michigan)"
cap label variable rurallabor_`loc'`yr' "Number of rural laborers (10000 persons) (Michigan)"
cap label variable gdp_michigan_`loc'`yr' "gdp (100 millian yuan) (Michigan)"
cap label variable gdp_sector2_mi_`loc'`yr' "gdp Sector 2 (100 millian yuan) (Michigan)"
cap label variable gdp_sector3_mi_`loc'`yr' "gdp Sector 3 (100 millian yuan) (Michigan)"
cap label variable va_sec1_`loc'`yr' "Value Added of Primary Industry (100 million yuan) (Michigan)"
cap label variable va_sec2_`loc'`yr' "Value Added of Secondary Industry (100 million yuan) (Michigan)"
cap label variable expval_`loc'`yr' "Value of Exports (1,000 US Dollars) (Michigan)"
cap label variable totemp_`loc'`yr' " (py)"
cap label variable gdp_py_`loc'`yr' " (py)"
cap label variable gdp_sect2_`loc'`yr' " (py)"
cap label variable gdp_sect3_`loc'`yr' " (py)"
cap label variable total_pop_`loc'`yr' " (py)"
cap label variable kmpr_`loc'`yr' " (py)"
cap label variable apr_`loc'`yr' " (py)"
cap label variable prpc_`loc'`yr' " (py)"
cap label variable num_bt_`loc'`yr' " (py)"
cap label variable avgsalary_`loc'`yr' " (py)"
cap label variable num_colstd_`loc'`yr' " (py)"
cap label variable givo_py_`loc'`yr' " (py)"
cap label variable givo_soe_`loc'`yr' " (py)"
cap label variable givo_colt_`loc'`yr' " (py)"
cap label variable exp_lgt_`loc'`yr' " (py)"
cap label variable num_hedu_`loc'`yr' " (py)"
cap label variable publibcol_`loc'`yr' " (py)"
cap label variable culland_`loc'`yr' " (py)"
cap label variable area_`loc'`yr' " (py)"
cap label variable emp_sect2_`loc'`yr' " (py)"
cap label variable emp_sect3_`loc'`yr' " (py)"
cap label variable fixinvest_`loc'`yr' " (py)"
cap label variable fdi_py_`loc'`yr' " (py)"
cap label variable a101_`loc'`yr' "Total no. of H                                            Table 2-19"
cap label variable a102_`loc'`yr' "Total P                                                            "
cap label variable a103_`loc'`yr' "Total M                                   H=household(s)           "
cap label variable a104_`loc'`yr' "Total F                                   M=male(s)                "
cap label variable a105_`loc'`yr' "Residents of urban wards: No. of H        F=female(s)              "
cap label variable a106_`loc'`yr' "                     : P               P=population (M+F)       "
cap label variable a107_`loc'`yr' "                     : M                                        "
cap label variable a108_`loc'`yr' "                     : F                                        "
cap label variable a109_`loc'`yr' "Residents of villages: No. of H                                    "
cap label variable a110_`loc'`yr' "                  : P                                           "
cap label variable a111_`loc'`yr' "                  : M                                           "
cap label variable a112_`loc'`yr' "                  : F                                           "
cap label variable a113_`loc'`yr' "Residents of rural units outside village jurisdiction: No. of H    "
cap label variable a114_`loc'`yr' "                                                  : P           "
cap label variable a115_`loc'`yr' "                                                  : M           "
cap label variable a116_`loc'`yr' "                                                  : F           "
cap label variable a117_`loc'`yr' "Non-agricultural H: P                                              "
cap label variable a118_`loc'`yr' "               : M                                              "
cap label variable a119_`loc'`yr' "               : F                                              "
cap label variable a120_`loc'`yr' "Agricultural H: P                                                  "
cap label variable a121_`loc'`yr' "           : M                                                  "
cap label variable a122_`loc'`yr' "           : F                                                  "
cap label variable a123_`loc'`yr' "Specially designated H and persons outside any H: P                "
cap label variable a124_`loc'`yr' "                                             : M                "
cap label variable a125_`loc'`yr' "                                             : F                "
cap label variable a126_`loc'`yr' "All residents of all zhen (townships) combined: No. of H  Table 2-11"
cap label variable a127_`loc'`yr' "                                       : P                  "
cap label variable a128_`loc'`yr' "                                       : M                  "
cap label variable a129_`loc'`yr' "                                       : F                  "
cap label variable a130_`loc'`yr' "Town residents in all zhen combined: No. of H                      "
cap label variable a131_`loc'`yr' "                                 : P                             "
cap label variable a132_`loc'`yr' "                                 : M                             "
cap label variable a133_`loc'`yr' "                                 : F                             "
cap label variable a134_`loc'`yr' "Rural residents in all zhen combined: No. of H                     "
cap label variable a135_`loc'`yr' "                                  : P                            "
cap label variable a136_`loc'`yr' "                                  : M                            "
cap label variable a137_`loc'`yr' "                                  : F                            "
cap label variable a138_`loc'`yr' "Non-agricultural H in all zhen combined: P                Table 2-12"
cap label variable a139_`loc'`yr' "                                     : M                         "
cap label variable a140_`loc'`yr' "                                     : F                         "
cap label variable a141_`loc'`yr' "Agricultural H in all zhen combined: P                             "
cap label variable a142_`loc'`yr' "                              : M                             "
cap label variable a143_`loc'`yr' "                           : F                                "
cap label variable a144_`loc'`yr' "Specially designated H, etc. in all zhen combined: P               "
cap label variable a145_`loc'`yr' "                                            : M               "
cap label variable a146_`loc'`yr' "                                            : F               "
cap label variable a181_`loc'`yr' "Total P, all ages and both sexes                                    A1"
cap label variable a182_`loc'`yr' "Total M, all ages                                                   A2"
cap label variable a183_`loc'`yr' "Total F, all ages                                                   A3"
cap label variable a184_`loc'`yr' "P 0-4                                                               A4"
cap label variable a185_`loc'`yr' "M 0-4                                                               A5"
cap label variable a186_`loc'`yr' "F 0-4                                                               A6"
cap label variable a187_`loc'`yr' "P 5-9                                                               A7"
cap label variable a188_`loc'`yr' "M 5-9                                                               A8"
cap label variable a189_`loc'`yr' "F 5-9                                                               A9"
cap label variable a190_`loc'`yr' "P 10-14                                                            A10"
cap label variable a191_`loc'`yr' "M 10-14                                                            A11"
cap label variable a192_`loc'`yr' "F 10-14                                                            A12"
cap label variable a193_`loc'`yr' "P 15-19                                                            A13"
cap label variable a194_`loc'`yr' "M 15-19                                                            A14"
cap label variable a195_`loc'`yr' "F 15-19                                                            A15"
cap label variable a196_`loc'`yr' "P 20-24                                                            A16"
cap label variable a197_`loc'`yr' "M 20-24                                                            A17"
cap label variable a198_`loc'`yr' "F 20-24                                                            A18"
cap label variable a199_`loc'`yr' "P 25-29                                                            A19"
cap label variable a200_`loc'`yr' "M 25-29                                                            A20"
cap label variable a201_`loc'`yr' "F 25-29                                                            A21"
cap label variable a202_`loc'`yr' "P 30-34                                                            A22"
cap label variable a203_`loc'`yr' "M 30-34                                                            A23"
cap label variable a204_`loc'`yr' "F 30-34                                                            A24"
cap label variable a205_`loc'`yr' "P 35-39                                                            A25"
cap label variable a206_`loc'`yr' "M 35-39                                                            A26"
cap label variable a207_`loc'`yr' "F 35-39                                                            A27"
cap label variable a208_`loc'`yr' "P 40-44                                                            A28"
cap label variable a209_`loc'`yr' "M 40-44                                                            A29"
cap label variable a210_`loc'`yr' "F 40-44                                                            A30"
cap label variable a261_`loc'`yr' "Total P aged 6+							  E1"
cap label variable a262_`loc'`yr' "Total M aged 6+							  E1"
cap label variable a263_`loc'`yr' "Total F aged 6+							  E1"
cap label variable a264_`loc'`yr' "P university                                                        E4"
cap label variable a267_`loc'`yr' "P technical/junior college                                          E7"
cap label variable a270_`loc'`yr' "P secondary technical school                                       E10"
cap label variable a273_`loc'`yr' "P senior middle school                                             E13"
cap label variable a276_`loc'`yr' "P junior middle school                                             E16"
cap label variable a279_`loc'`yr' "P primary school                                                   E19"
cap label variable a361_`loc'`yr' "Total inmigrants                                                    R1"
cap label variable a362_`loc'`yr' "Within-province inmigrants: Total                                   R2"
cap label variable a363_`loc'`yr' "                       : from municipal cities                   R3"
cap label variable a364_`loc'`yr' "                       : from zhen (urban townships)             R4"
cap label variable a365_`loc'`yr' "                       : from xiang (rural townships)            R5"
cap label variable a366_`loc'`yr' "Inmigrants from other provinces: Total                              R6"
cap label variable a367_`loc'`yr' "                         : from municipal cities                 R7"
cap label variable a368_`loc'`yr' "                         : from zhen                             R8"
cap label variable a369_`loc'`yr' "                         : from xiang                            R9"
cap label variable a370_`loc'`yr' "Other inmigrants                                                   R10"
cap label variable a381_`loc'`yr' "Total employed P                                                    I1"
cap label variable a384_`loc'`yr' "P Agric./forestry/animal husb./fishery/water conservancy            I4"
cap label variable a387_`loc'`yr' "P Industry                                                          I7"
cap label variable a390_`loc'`yr' "P Mining, prospecting                                              I10"
cap label variable a393_`loc'`yr' "P Construction                                                     I13"
cap label variable a396_`loc'`yr' "P Transport, posts, telecommunications                             I16"
cap label variable a399_`loc'`yr' "P Commerce, supply and marketing                                   I19"
cap label variable a402_`loc'`yr' "P Real estate, utilities, residential services                     I22"
cap label variable a405_`loc'`yr' "P Medicine, health care, sports, welfare                           I25"
cap label variable a408_`loc'`yr' "P Education, culture, arts, radio, television                      I28"
cap label variable a411_`loc'`yr' "P Science, technology                                              I31"
cap label variable a414_`loc'`yr' "P Finance, insurance                                               I34"
cap label variable a417_`loc'`yr' "P Government, party, and NGOs                                      I37"
cap label variable a420_`loc'`yr' "P Other economic activities                                        I40"
cap label variable a431_`loc'`yr' "P Professional and high-level technical personnel                   O1"
cap label variable a434_`loc'`yr' "P Officials/managers in gov't, party, business, & NGOs              O4"
cap label variable a437_`loc'`yr' "P Clerical personnel                                                O7"
cap label variable a440_`loc'`yr' "P Employees in commercial sector                                   O10"
cap label variable a443_`loc'`yr' "P Employees in service sector                                      O13"
cap label variable a446_`loc'`yr' "P Workers in agric., forestry, animal husb., fisheries             O16"
cap label variable a449_`loc'`yr' "P Workers in manufacturing, construction, transport, etc.          O19"
cap label variable a452_`loc'`yr' "P Other and misc. occupations                                      O22"
cap label variable c_totalPop_`loc'`yr' 				"census total pop"
cap label variable c_emp_`loc'`yr'                  "census total emp"
cap label variable c_emp_ag_`loc'`yr'         " census agricultural emp"
cap label variable c_emp_min_`loc'`yr'       "census mining emp"
cap label variable c_emp_man_`loc'`yr'                      "census manufacturing emp"
cap label variable c_emp_man_trad_`loc'`yr'           "census manu trad emp"
cap label variable c_emp_man_chem_`loc'`yr'        "census manu chem emp"
cap label variable c_emp_man_hvy_`loc'`yr'            "census manu heavy emp"
cap label variable c_emp_man_hitech_`loc'`yr'       "census manu hightech emp"
cap label variable c_emp_util_`loc'`yr'                         "census util emp"
cap label variable c_emp_cons_`loc'`yr'                      "census cons emp"
cap label variable c_emp_soft_`loc'`yr'                       "census soft emp"
cap label variable c_emp_whsl_`loc'`yr'                      "census wholesale emp"
cap label variable c_emp_fina_`loc'`yr'                        "census finance emp"
cap label variable c_emp_res_`loc'`yr'                         "census res emp"
cap label variable c_emp_cul_`loc'`yr'                        "  census cul emp"
cap label variable c_emp_pub_`loc'`yr'                       "census pub emp"
cap label variable c_emp_tran_`loc'`yr'                       "census transportaion emp"
cap label variable c_rur_Mig_`loc'`yr'           "census rural migrant"
cap label variable c_urb_Mig_`loc'`yr'          "census urban migrant"
cap label variable c_rur_mig_19to55__`loc'`yr'        "census rural migrant 19-55"
cap label variable c_rur_mig_19to55_h_`loc'`yr'      "census rural migrant 19-55 high"
cap label variable c_urb_mig_19to55__`loc'`yr'       "census urban migrant 19-55"
cap label variable c_urb_mig_19to55_h_`loc'`yr'     "census urban migrant 19-55 high"
cap label variable c_f_19to55_`loc'`yr'                         "census female 19-55"
cap label variable c_f_Under19_`loc'`yr'                     "census female <19"
cap label variable c_f_Over55_`loc'`yr'                        "census female >55"
cap label variable c_f_19to55_h_`loc'`yr'                    "census female 19-55 high"
cap label variable c_f_19to55_w__`loc'`yr'                "census female 19-55 work"
cap label variable c_f_19to55_w_h_`loc'`yr'                              "census female 19-55 work high"
cap label variable c_f_19to55_w_c_`loc'`yr'                              "census female 19-55 work college"
cap label variable c_m_19to55_`loc'`yr'      "census male 19-55"
cap label variable c_m_Under19_`loc'`yr'                   "census male <19"
cap label variable c_m_Over55_`loc'`yr'                      "census male >55"
cap label variable c_m_19to55_h_`loc'`yr'                  "census male 19-55 high"
cap label variable c_m_19to55_w__`loc'`yr'                              "census male 19-55 work"
cap label variable c_m_19to55_w_h_`loc'`yr'           "census male 19-55 work high"
cap label variable c_m_19to55_w_c_`loc'`yr'            "census male 19-55 work college"
cap label variable c_rur_mig_A_`loc'`yr'                      "census rural migrantA"
cap label variable c_urb_mig_A_`loc'`yr'                     "census urban migrant A"
cap label variable c_rur_mig_19to55_A_`loc'`yr'     "census rural migrant 19-55 A"
cap label variable c_rur_mig_19to55_h_A_`loc'`yr'    "census rural migrant 19-55 high A"
cap label variable c_urb_mig_19to55_A_`loc'`yr'    "census urban migrant 19-55 A"
cap label variable c_urb_mig_19to55_h_A_`loc'`yr'               "census urban migrant 19-55 high A"
cap label variable c_rur_ob__`loc'`yr'                           "census rural out birth"
cap label variable c_urb_ob__`loc'`yr'                          "census urban out birth"
cap label variable c_rur_ob_19to55__`loc'`yr'          "census rural out birth 19-55"
cap label variable c_rur_ob_19to55_h_`loc'`yr'        "census rural out birth 19-55 high"
cap label variable c_urb_ob_19to55__`loc'`yr'         "census urban out birth 19-55"
cap label variable c_urb_ob_19to55_h_`loc'`yr'       "census urban out birth 19-55 high"
cap label variable c_rur_ob_A1_`loc'`yr'                     "census rural out birth A1"
cap label variable c_urb_ob_A1_`loc'`yr'                    "census urban out birth A1"
cap label variable c_rur_ob_19to55_A1_`loc'`yr'     "census rural out birth 19-55 A1"
cap label variable c_rur_ob_19to55_h_A1_`loc'`yr'                "census rural out birth 19-55 high A1"
cap label variable c_urb_ob_19to55_A1_`loc'`yr'    "census urban out birth 19-55 A1"
cap label variable c_urb_ob_19to55_h_A1_`loc'`yr'               "census urban out birth 19-55 high A1"
cap label variable c_rur_ob_A2_`loc'`yr'                     "census rural out birth A2"
cap label variable c_urb_ob_A2_`loc'`yr'                    "census urban out birth A2"
cap label variable c_rur_ob_19to55_A2_`loc'`yr'     "census rural out birth 19-55 A2"
cap label variable c_rur_ob_19to55_h_A2_`loc'`yr'                "census rural out birth 19-55 high A2"
cap label variable c_urb_ob_19to55_A2_`loc'`yr'    "census urban out birth 19-55 A2"
cap label variable c_urb_ob_19to55_h_A2_`loc'`yr'               "census urban out birth 19-55 high A2"
cap label variable actpop_`loc'`yr'  "census population from 2010 aggregate data"
}
}

sort cc05
save ..\..\data\tabular_data_BJ\generated\combined.dta, replace


log close

erase cp90a.dta
erase cp90.dta
erase prefb.dta
erase prefa.dta
erase pref.dta
erase cpt.dta
erase temp90.dta
erase xwtemp.dta
